import Vue from 'vue';
import VueRouter from 'vue-router';
Vue.use(VueRouter);

const Login = () => import('../components/Login');
const Layout = () => import('../components/Layout');
const PackageManagement = () => import('../components/PackageManagement');
const PlatformManagement = () => import('../components/PlatformManagement');
// const Home = () => import('../components/Home');

// 开发者
const DeveloperFunction = () => import('../components/DeveloperFunction');
// const Home = () => import('../components/Home');
// developers
const routes = [
  {
    path: '/',
    name: 'layout',
    component: Layout,
    children: [
      {
        path: '/login',
        name: 'login',
        component: Login
      },
      {
        path: '/platform/platformmanagement',
        name: 'platformManagement',
        component: PlatformManagement
      },
      {
        path: '/platform/packagemanagement',
        name: 'packageManagement',
        component: PackageManagement
      },
      {
        path: '/developer/function',
        name: 'DeveloperFunction',
        component: DeveloperFunction
      },
      {
        path: '/404',
        name: 'page404',
        component: Login
      },
      {
        path: '/',
        redirect: '/login'
      }
    ]
  }
];

const router = new VueRouter({
  base: '/platform',
  routes,
  mode: 'history'
});
// 全局路由守卫
// router.beforeEach((to, from, next) => {
//   if (!to.matched.length) {
//     if (from.path !== '/404') {
//       next({ path: '/404' });
//     }

//     return;
//   }
//   let token = localStorage.getItem('token');
//   if (token) {
//     next();
//   } else {
//     next();
//     next({path: '/login'});
//   }
// });
export default router;
